package operations;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class BorrowedOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("借阅书籍");
        System.out.print("请输入你要借阅的书籍的名字：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        int currentsize = bookList.getUsedsize();
        for (int i = 0; i < currentsize; i++) {
            Book book = bookList.getPos(i);
            if(name.equals(book.getName())){
                if(book.isBorrowed() == true){
                    System.out.println("书籍已经被借走了");
                    return;
                }
                book.setBorrowed(true);
                System.out.println("借阅书籍成功");
                return;
            }
        }
        System.out.println("没有你要借阅的书籍");
    }
}
